/**
 * 递归求和
 * Created by zhaoxin on 2018/7/25.
 */
public class Sum {

    public int sum(int [] arr){
        return sum(arr, 0);
    }

    /**
     * 对用户隐藏的实际求和递归函数
     * @param arr
     * @param l
     * @return
     */
    private int sum(int [] arr, int l){
        if (l == arr.length) {
            return 0;
        }
        return arr[l] + sum(arr, l + 1);
    }


    public static void main(String[] args) {
        int [] arr = {1, 2, 3, 4, 5};
        System.out.println(new Sum().sum(arr));

    }
}
